package config

import (
	"gitee.com/wochong/HalloGin/database/mysql"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

var (
	config *Conf
)

//Conf Return conf.yml mapper
type Conf struct {
	Version     string          `yaml:"version"`
	APIAddr     string          `yaml:"api_addr"`
	MysqlConfig *mysql.MysqlOpt `yaml:"mysql_opt"`
}

// LoadConfOrDie Loading config from local file
func LoadConfOrDie(confFile, version string) {
	config = &Conf{}
	yamlFile, err := ioutil.ReadFile(confFile)
	if err != nil {
		log.Fatalf("Open Configure file failed, %v ", err)
	}
	err = yaml.Unmarshal(yamlFile, config)
	if err != nil {
		log.Fatalf("Unmarshal, %v ", err)
	}
}

//Get return config
func Get() *Conf {
	return config
}
